package ExceptionDemo;

public class exceptiondemo2
{
    public static void main(String[] args) {
        //目标：认识自定义运行时异常
        System.out.println("程序开始进行。。。");
        try {
            saveAge(250);
            System.out.println("保存年龄成功。。。");
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("保存年龄失败。。。");
        }
        System.out.println("程序结束。。。");
    }

    private static void saveAge(int age) {
        if(age < 1 ||age > 200 )
        {
            throw new MyRuntimeException("年龄非法！！！");
        }
        else
        {
            System.out.println("保存年龄成功：" + age);
        }

    }
}
